/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package example;

import andreafrancia.remoted.RemotizationFailedException;
import andreafrancia.remoted.Remotizer;
import java.rmi.AlreadyBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import java.util.AbstractList;
import java.util.List;

/**
 *
 * @author Andrea Francia andrea.francia at gmx dot org
 */
public class ServerImpl implements Server {

    public List<String> getRemotizedList() throws RemotizationFailedException {
        // create a non serializable List
        List<String> list = new AbstractList<String>() {

            @Override
            public String get(int index) {
                return "Value " + index;
            }

            @Override
            public int size() {
                return 5;
            }
        };
        
        return Remotizer.remotize(list);
    }
    
    public static void main(String[] args) 
            throws RemoteException, 
                   AlreadyBoundException 
    {
        Server server = new ServerImpl();
        Remote remote = UnicastRemoteObject.exportObject(server, 0);
        LocateRegistry.createRegistry(1099).bind("test", remote);
        System.err.println("Server ready.");
    }
}
